<?php session_start();
include "../conexao.php";

if (!isset($_SESSION["txt_login"]) and !isset($_SESSION["txt_senha"]))
{ print "<script type = 'text/javascript'> location.href = 'login.php'</script>"; exit();}

    include "funcoes.php";
	if($_POST["txt_datainicial"]!=""){
	$data1 = $_POST["txt_datainicial"];
	$data2 = $_POST["txt_datafinal"];
	
	
	
	$dta1 = $_POST["txt_datainicial"];
	$dta2 = $_POST["txt_datafinal"];
	}
	
	if($_GET["txt_datainicial"]!="" && $_POST["txt_datainicial"]==""){
	$data1 = $_GET["txt_datainicial"];
	$data2 = $_GET["txt_datafinal"];
	
	$dta1 = $_GET["txt_datainicial"];
	$dta2 = $_GET["txt_datafinal"];
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
<title>&Aacute;rea Administrativa</title>

<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">



try{
xmlhttp = new XMLHttpRequest();
}
catch(ee){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E){
xmlhttp = false;
}
}
}

function abrePesquisa(arquivo,metodo){
xmlhttp.open(metodo,arquivo);
xmlhttp.onreadystatechange=conteudo
xmlhttp.send(null)
}

function conteudo() {
document.getElementById('conteudo').innerHTML="carregando... ";
if (xmlhttp.readyState==4){
document.getElementById('conteudo').innerHTML=xmlhttp.responseText
}
}<!--<img src='images/indicator_verybig.gif' width='100' alt=''/> -->
</script>
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
	font-size: 16px;
}
.style2 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
</head>

<body>

<div id="todo">
	

	<div id="meio">
		
<div id="conteudo">
		<div id="miolo">
			<div class="secao_miolo">
			  <div id="conteudo"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="tarja2"><form id="form1" name="form1" method="post" action="principal.php?link=20" onsubmit="return criticaperiodo()">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="13%">&nbsp;</td>
                <td width="22%"><div align="center"><strong>&nbsp;&nbsp;Data inicial</strong> </div></td>
                <td width="1%">&nbsp;</td>
                <td width="14%">
                 
                    <input name="txt_datainicial" type="text" id="txt_datainicial" value="<?php if ($data1 != "") {echo $data1; } ?>" />
                </td>
                <td width="20%"><div align="center"><strong>&nbsp;&nbsp;Data final</strong></div></td>
                <td width="5%">&nbsp;</td>
                <td width="16%">
               
                    <input name="txt_datafinal" type="text" id="txt_datafinal" value="<?php if ($data2 != "") {echo $data2; }else{echo date("d/m/Y");} ?>" />
               </td>
                <td width="9%"><input type="submit" name="Submit" value="Enviar" /></td>
               
              </tr>
              <tr>
                <td colspan="3">Obs. A contagem das visitas come&ccedil;aram a partir do dia 24/03/2011</td>
                <td><div align="center">dd/mm/aaaa</div></td>
                <td colspan="2">&nbsp;</td>
                <td><div align="center">dd/mm/aaaa</div></td>
                <td colspan="3">&nbsp;</td>
              </tr>
            </table>
                    </form>
          </td>
        </tr>
      </table>
      <strong>   	  
	 <br />
      </strong><?php if($_POST["txt_datainicial"]!="" || $_GET["txt_datainicial"]){?>
      <table width="100%" height="22" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td align="center" background="imagens/img_cat.gif"><span class="style1">Visitas por Per&iacute;odo</span></td>
        </tr>
      </table>
      <strong>      </strong></div></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="2" cellpadding="0">
      <tr>
        <td width="15%">&nbsp;</td>
        <td width="19%"class="paginacao"><div align="center"><strong>Data</strong></div></td>
        <td width="8%"class="paginacao"><div align="center"><strong>Visitas<br />
        </strong></div></td>
        <td width="16%">&nbsp;</td>
      </tr>
		
		<?php 
			$data1 = databr($data1,1);
			$data2 = databr($data2,1);
			
			 if($pagina=="")
		{
			$pagina =1;
		} 
		if($pagina=="0")
		{
			$pagina =1;
		} 
			
			
			$maximo = 1000000000;
			$inicio = ($pagina * $maximo) - $maximo;
			
			
			$sql = "SELECT data, visitas FROM visitas WHERE data >= '$data1' and data <= '$data2' ORDER BY id_visitas LIMIT $inicio, $maximo";
			//echo $sql;
			$qry = mysql_query($sql);
			while ($linha = mysql_fetch_array($qry)){
			$total = $total + $linha["visitas"];
			
			
			?>
      <tr>
        <td align="center"></span></td>
        <td align="center" class="meio"><?php 
		echo date("d/m/Y", strtotime("".$linha['data'].""));
		echo "<br>";
		echo $linha['hora_pedido'];
		?></span></td>
        <td align="center" class="meio"><?php echo $linha['visitas']; ?></td>
        <td align="center">&nbsp;</td>
      </tr><?php } ?>
      <tr>
        <td align="center" >&nbsp;</td>
        <td align="center" class="meio"><span class="style2">Total</span></td>
        <td align="center" class="meio"><span class="style2"><?php echo $total; ?></span></td>
        <td align="center">&nbsp;</td>
      </tr>
	  
    </table>
    <?php }?></td>
  </tr>
  <tr>
    <td>
	</td>
  </tr>
</table></div>
		  </div>
			</div></div>
		<div style="clear: both;"></div>
	</div>

	
</div>

</body>
</html>